#!/usr/bin/perl
print "---------------------------------------\n";
print "root name = $ARGV[0]\n";
print "# of bins = $ARGV[1]\n";
print "---------------------------------------\n";

$numArgs = $#ARGV + 1;

if ($numArgs != 2) {
    print "ERROR: command line args, ($numArgs/2)\n";
    print "USAGE: collectPlots.pl [root name] [number of bins]\n";
    exit(1);
}

$ROOT = $ARGV[0];
$NBINS = $ARGV[1];
$PLOTDIR = "plots/PLOTS_${ROOT}/";

print "=> mkdir -p ${PLOTDIR} \n";
system("mkdir -p ${PLOTDIR}");

$SPECT_DIR = "spectra/";
$PLOTNAME = "PLOT_mag_phase.ps";
$DATANAME = "indata.dat";
$DATA_DIR = "bins/";

for ($N=0;$N<=$NBINS;$N++) {
    print "\n(BIN $N)\n";
    print "== copying spectrum  : ${SPECT_DIR}${ROOT}-bin${N}/${PLOTNAME}\n";
    system("cp ${SPECT_DIR}${ROOT}-bin${N}/${PLOTNAME} ${PLOTDIR}/PLOT_mag_phase_${N}.ps");
    print "== copying data plot : ${DATA_DIR}${ROOT}-bin${N}.ps\n";
    system("cp ${DATA_DIR}${ROOT}-bin${N}.dat.ps  ${PLOTDIR}");
    print "== copying data file : ${DATA_DIR}${ROOT}.*\n";
    system("cp ${DATA_DIR}${ROOT}-bin${N}.dat  ${PLOTDIR}/.");
    print "== copying data file2: ${SPECT_DIR}${ROOT}-bin${N}/indata.dat\n";
    system("cp ${SPECT_DIR}${ROOT}-bin${N}/indata.dat ${PLOTDIR}/indata_${N}.dat");
}

system("cp ${DATA_DIR}${ROOT}.*  ${PLOTDIR}/.");
